﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Zombie_Demo.Utilities
{
    public static class ErrorManager
    {
        private static List<Exception> errors = new List<Exception>();
        private static List<string> customErrors = new List<string>();

        public static void AddError(Exception e)
        {
            errors.Add(e);
        }

        public static void AddError(string error)
        {
             customErrors.Add("Custom error: " + error);
        }

        public static void PrintAllErrors()
        {
            foreach (Exception e in errors)
            {
                Console.WriteLine(e.ToString());
            }
            Console.WriteLine("Number of errors: " + errors.Count.ToString());

            SaveAllErrors();
        }

        public static void SaveAllErrors()
        {
            TextWriter w = new StreamWriter(@"errors.txt");
            foreach (Exception e in errors)
            {
                w.Write(e);
                w.Write(w.NewLine);
            }
            w.Write("Number of errors: " + errors.Count.ToString());
            w.Close();
        }
    }
}
